package com.yogee.topseller.fragment.productdetail;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yogee.core.base.HttpFragment;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.ProductDetailsActivity;
import com.yogee.topseller.adapter.ProductInterestedRvAdapter;
import com.yogee.topseller.bean.ProductInfoBean;
import com.yogee.topseller.view.MyScrollView;
import com.yogee.topseller.view.PublicStaticClass;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 相关产品
 * Created by zwj on 2017/12/7.
 */

public class ProductListFragment extends BaseFragment implements ProductDetailsActivity.UpdateListener{

    @BindView(R.id.id_stickynavlayout_innerscrollview)
    RecyclerView interestedRv;

    @BindView(R.id.oneScrollview)
    MyScrollView oneScrollView;


    private ProductInterestedRvAdapter interestedRvAdapter;

    public List<ProductInfoBean.InterestBean> list = new ArrayList<>();
    private ProductInfoBean beans;

    Unbinder unbinder1;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_product_prolist;
    }


    @Override
    protected void initView() {
        ((ProductDetailsActivity)getActivity()).setListener(this);
        beans = (ProductInfoBean) getArguments().getSerializable("baseInfo");
        list = beans.getInterest();
        interestedRv.setLayoutManager(new LinearLayoutManager(getActivity()));
        interestedRvAdapter = new ProductInterestedRvAdapter(getActivity());
        interestedRv.setAdapter(interestedRvAdapter);
        interestedRvAdapter.addData(list);

        oneScrollView.setScrollListener(new MyScrollView.ScrollListener() {
            @Override
            public void onScrollToBottom() {

            }

            @Override
            public void onScrollToTop() {

            }

            @Override
            public void onScroll(int scrollY) {
                if (scrollY == 0) {
                    PublicStaticClass.IsTop = true;
                } else {
                    PublicStaticClass.IsTop = false;
                }
            }

            @Override
            public void notBottom() {

            }

        });

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder1.unbind();
    }

    @Override
    public String getTitle() {
        return "相关产品";
    }

    @Override
    public void updateList(ProductInfoBean bean) {
        interestedRvAdapter.addData(bean.getInterest());
    }
}
